package com.jeason.fileserver.service;

import cn.hutool.core.bean.BeanUtil;
import com.jeason.fileserver.domain.LoginUser;
import com.jeason.fileserver.entity.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author: jeason
 * @Description:
 * @Date: 2021/1/17 19:17
 */
@Service
public class LoginService {
    @Autowired
    private SysUserService userService;

    public LoginUser login(String username, String password) {
        SysUser user = userService.loadUserByUsername(username);
        if (user == null){
            throw new RuntimeException("用户不存在");
        }
        if (!user.getPassword().equals(password)){
            throw new RuntimeException("密码不对");
        }
        LoginUser loginUser = new LoginUser();
        BeanUtil.copyProperties(user,loginUser);
        return loginUser;
    }
}
